package com.concurrent.chapter1.concurrent05;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
	public static void main(String[] args) {
		File file1 = new File("/Users/shangyidong/Documents/whitelist/500000-2000000.txt");
		File file2 = new File("/Users/shangyidong/Documents/whitelist/2000000-5000000.txt");
		File file3 = new File("/Users/shangyidong/Documents/whitelist/5000000+.txt");
		
		List<String> list1 = new ArrayList<String>();
		List<String> list2 = new ArrayList<String>();
		List<String> list3 = new ArrayList<String>();

		if(file1.isFile() && file1.exists()){ //判断文件是否存在
            InputStreamReader read;
			try {
				read = new InputStreamReader(new FileInputStream(file1));
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while((lineTxt = bufferedReader.readLine()) != null){
					//System.out.print(lineTxt + ",");
					list1.add(lineTxt);
				}
				read.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(file2.isFile() && file2.exists()){ //判断文件是否存在
            InputStreamReader read;
			try {
				read = new InputStreamReader(new FileInputStream(file2));
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while((lineTxt = bufferedReader.readLine()) != null){
					//System.out.print(lineTxt + ",");
					list2.add(lineTxt);
				}
				read.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(file3.isFile() && file3.exists()){ //判断文件是否存在
            InputStreamReader read;
			try {
				read = new InputStreamReader(new FileInputStream(file3));
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while((lineTxt = bufferedReader.readLine()) != null){
					//System.out.print(lineTxt + ",");
					list3.add(lineTxt);
				}
				read.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		System.out.println(list1.size());
		System.out.println(list2.size());
		System.out.println(list3.size());
		
		List<String> newList1 = new ArrayList<String>();
		List<String> newList2 = new ArrayList<String>();
		List<String> newList3 = new ArrayList<String>();
		
		for (String string : list1) {
			if (list2.contains(string) || list3.contains(string)) {
				continue;
			}
			newList1.add(string);
		}
		for (String string : list2) {
			if (list3.contains(string)) {
				continue;
			}
			newList2.add(string);
		}
		for (String string : list3) {
			newList3.add(string);
		}
		
		System.out.println(newList1.size());
		System.out.println(newList2.size());
		System.out.println(newList3.size());
		
		for (String string : newList2) {
			System.out.print(string + ",");
		}
	}
}
